class Person {
  String name;
  static Person? instance;

  // 在工厂构造函数中不能使用this指向
  factory Person([String name = '']) {
    if (Person.instance == null) {
      Person.instance = Person.newSelf(name);
    }
    return Person.instance!;
  }
  // 命名构造函数
  Person.newSelf(this.name);

  // 修改name的值
  setName(String name) {
    this.name = name;
  }
}

void main() {
  Person p1 = new Person("何紫怡");
  Person p2 = new Person("何紫怡2");
  print(p2.name);
  print(p1 == p2);
  p2.setName('何紫怡3');
  print(p1.name);
  p1.name = "123";
  print(p2.name);
}
